import { shapeFlags } from '../share/shapeFlag'

export function initSlots (instance, children) {
  const {vnode} =  instance
  if(vnode.shapeFlag &shapeFlags.SLOT_CHILDREN) {
    normalizeObjectSlots(children, instance.slots)
  }
}

function normalizeObjectSlots(children, slots) {
  for(const key in children) {
    const value = children[key]
    slots[key] = (arg)=> normalizeSlotValue(value(arg))
  }
}

function normalizeSlotValue(children) {
  return Array.isArray(children) ? children : [children]
} 